package com.example.vspm.controller;

import com.example.vspm.entity.Person;
import com.example.vspm.entity.Result;
import com.example.vspm.service.impl.LoginServiceImpl;
import com.example.vspm.service.impl.PersonServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@RestController
public class LoginController {
    @Autowired
    private LoginServiceImpl lsi;
    @Autowired
    private PersonServiceImpl psi;

    @GetMapping("/index")
    public String indexAction() {
        System.out.println("执行了index方法");
        return "接口来啦";
    }
    @GetMapping("/log")
    public Person logAction(Person person){
        System.out.println("调用了log接口");
        return person;
    }
    @GetMapping("/login")
    public Result loginAction(Person person, HttpSession session,Model model) {
        Result res = lsi.login(person, session);
        Object obj = session.getAttribute("person");
        Person per = (Person)obj;
        System.out.println("执行了login方法"+per);
      model.addAttribute("res",res);
      return res;
    }
    @GetMapping("/findPerson")
    public Person findPersonAction(int pid){
        Person per = psi.selectPerson(pid);
        return per;
    }
}


